package com.example.dubbo.account.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dubbo.account.dao.AccountTblDao;
import com.example.dubbo.account.entity.AccountTblEntity;
import com.example.dubbo.account.service.AccountTblService;
import com.example.dubbo.api.dto.AccountDTO;
import com.example.dubbo.api.enums.RspStatusEnum;
import com.example.dubbo.api.response.ObjectResponse;
import org.springframework.stereotype.Service;



@Service("accountTblService")
public class AccountTblServiceImpl extends ServiceImpl<AccountTblDao, AccountTblEntity> implements AccountTblService {

    @Override
    public ObjectResponse decreaseAccount(AccountDTO accountDTO) {
        int account = baseMapper.decreaseAccount(accountDTO.getUserId(), accountDTO.getAmount().doubleValue());
        ObjectResponse<Object> response = new ObjectResponse<>();
        if (account > 0){
            response.setStatus(RspStatusEnum.SUCCESS.getCode());
            response.setMessage(RspStatusEnum.SUCCESS.getMessage());
            return response;
        }

        response.setStatus(RspStatusEnum.FAIL.getCode());
        response.setMessage(RspStatusEnum.FAIL.getMessage());
        return response;
    }
}